package org.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.bean.O2ranktap;
import org.dao.TapDao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class TapDaoImpl extends HibernateDaoSupport implements TapDao {

	@SuppressWarnings("rawtypes")
	@Override
	public List queryForPageTap(final String hql, final int offset,
			final int length) {
		List list = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery(hql);
				query.setFirstResult(offset);
				query.setMaxResults(length);
				List list = query.list();

				return list;
			}
		});
		return list;
	}
	
	@Override
	public int getAllRowCount(String hql) {
		return getHibernateTemplate().find(hql).size();

	}
	
	@SuppressWarnings("unchecked")
	@Override
	public O2ranktap selectbyuid(int uid) {
		// TODO Auto-generated method stub
		String hql = "from O2ranktap t where t.uid="+uid;
		List<O2ranktap> o2ranktap = (List<O2ranktap>)this.getHibernateTemplate().find(hql);
		
		if(o2ranktap.size()!=0){
			return o2ranktap.get(0);
		}
		else{
		
		return null;
		}
	}
}
